package cn.hexcloud.dga.governance.assessor.spec;

import cn.hexcloud.dga.governance.assessor.Assessor;
import cn.hexcloud.dga.governance.bean.AssessParam;
import cn.hexcloud.dga.governance.bean.GovernanceAssessDetail;
import cn.hexcloud.dga.meta.bean.TableMetaInfo;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;

@Component("TABLE_COMMENT")
public class TableCommentAssessor extends Assessor {
    @Override
    public void checkProblem(GovernanceAssessDetail governanceAssessDetail, AssessParam assessParam) throws Exception {
        TableMetaInfo tableMetaInfo = assessParam.getTableMetaInfo();
        String tableComment = tableMetaInfo.getTableComment();
        if (tableComment == null || tableComment.trim().length() == 0) {
            governanceAssessDetail.setAssessScore(BigDecimal.ZERO);
            governanceAssessDetail.setAssessProblem("未填写表注释");
            String governanceUrl = assessParam.getGovernanceMetric().getGovernanceUrl().replace("{tableId}", tableMetaInfo.getId().toString());
            governanceAssessDetail.setGovernanceUrl(governanceUrl);
        }
    }
}
